package com.ruoyan.controller;

import com.ruoyan.pojo.Employee;
import com.ruoyan.service.DepartmentService;
import com.ruoyan.service.EmployManageService;
import com.ruoyan.service.SalaryManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Package: com.ruoyan.controller
 * @ClassName: SalaryManageController
 * @Author: ruoyan1998
 * @CreateTime: 2021/6/3 15:21
 * @Description: 工资管理Controller
 */
@Controller
public class SalaryManageController
{
    @Autowired
    private SalaryManageService salaryManageService;

    @GetMapping("/salary")
    public String salaryList(Model model)
    {
        List<Employee> employeeSalaryList = salaryManageService.queryEmployeeSalaryList();

        model.addAttribute("employeeSalaryList",employeeSalaryList);

        return "salary/salaryList";
    }

    @GetMapping("/toUpdateSal/{id}")
    public String toUpdateSalary(@PathVariable("id") int id, Model model)
    {
        Employee queryEmployeeSalaryById = salaryManageService.queryEmployeeSalaryById(id);

        model.addAttribute("employeeSalary",queryEmployeeSalaryById);

        return "salary/update";
    }

    @PostMapping("/salaryUpdate")
    public String updateSalary(Employee employee)
    {
        int employeeSalary = salaryManageService.updateEmployeeSalary(employee);

        if(employeeSalary <= 0)
        {
            return "salary/updateError";
        }

        return "redirect:/salary";
    }
}
